package com.bdf.ipharma.gui;

import java.awt.Insets;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.SwingConstants;

import com.bdf.ipharma.starter.McdError;

/**
 * A Swing-based button class.
 * IPHARMA 2011
 * @author jmazzetti
 */
public class GUIButtonImage extends JButton
{
  /**
   * Attributes
   */
  Insets margin = new Insets( 0, 0, 0, 0 );
  ImageIcon imageDown;

  /**
   * Constructs a new instance.
   */
  public GUIButtonImage( ImageIcon pUp, ImageIcon pDown )
  {
    super( pUp );
    try
    {
      imageDown = pDown;
      jbInit();
    }
    catch (Exception e)
    {
      McdError.add( e );
    }
  }

  /**
   * Constructs a new instance.
   */
  public GUIButtonImage( String pText, ImageIcon pUp, ImageIcon pDown )
  {
    super( pText, pUp );
    try
    {
      imageDown = pDown;
      jbInit();
    }
    catch (Exception e)
    {
      McdError.add( e );
    }
  }

  /**
   * Initializes the state of this instance.
   */
  private void jbInit() throws Exception
  {
    setRequestFocusEnabled( false );
    setPressedIcon( imageDown );
    setContentAreaFilled( false );
    setBorderPainted( false );
    setBorder( BorderFactory.createEmptyBorder( 0, 0, 0, 0 ) );
    setMargin( margin );
    setHorizontalTextPosition( SwingConstants.CENTER );
    setVerticalTextPosition( SwingConstants.CENTER );
  }
}